package com.cassiopae.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class User implements Serializable{
	private static final long serialVersionUID = 1L;
	private String nom;
	private String prenom;
	private String login;
	private String email;
	private String pwd;
	private Boolean activateOrNot;
	private String type;
	private List<Profile> profiles;

	public User() {
		this.nom = "";
		this.prenom = "";
		this.login = "";
		this.email = "";
		this.pwd = "";
		this.activateOrNot = false;
		this.type = "";
		profiles = new ArrayList<Profile>();
	}

	public User(String nom, String prenom, String login, String email, String pwd,
			Boolean activateOrNot, String type) {
		this.nom = nom;
		this.prenom = prenom;
		this.login = login;
		this.email = email;
		this.pwd = pwd;
		this.activateOrNot = activateOrNot;
		this.type = type;
		profiles = new ArrayList<Profile>();
	}
	
	public void init(String _email){
		String emailTab[] = _email.split("@");
		String prenomNom[] = emailTab[0].split("\\.");
		String prenom = prenomNom[0];
		String nom = prenomNom[1];
		login = "";
		int i = 0;
		while(i<prenom.length() && prenom.charAt(i) != '-'){
			if(i == 0){
				login = ( ""+prenom.charAt(i) ).toUpperCase();
			}else{
				login += prenom.charAt(i);
			}
			i++;
		}
		login += ( ""+nom.charAt(0) ).toUpperCase();
		this.nom = nom.toUpperCase();
		this.prenom = prenom;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String _email) {
		this.email = _email;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public Boolean getActivateOrNot() {
		return activateOrNot;
	}

	public void setActivateOrNot(Boolean activateOrNot) {
		this.activateOrNot = activateOrNot;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<Profile> getProfiles() {
		return profiles;
	}

	public void setProfiles(List<Profile> profiles) {
		this.profiles = profiles;
	}

	@Override
	public String toString() {
		return "User [nom=" + nom + ", prenom=" + prenom + ", login=" + login
				+ ", pwd=" + pwd + ", activateOrNot=" + activateOrNot
				+ ", type=" + type + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		return true;
	}

}
